package com.szqhyxj.youxiangju.biz.merchantHome.shop.site;

import com.szqhyxj.youxiangju.biz.merchantHome.bean.DefaultSite;
import com.szqhyxj.youxiangju.sys.BaseResult;
import com.szqhyxj.youxiangju.sys.RetrofitFacade;

import java.util.List;

import io.reactivex.Observable;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;

/**
 * XiaoPanYu
 * on 2018/11/3
 */
public class SiteModel{

    public interface SiteService {

        @POST("address/getDefault")
        Observable<BaseResult<DefaultSite>> getDefaultAddress();

        @FormUrlEncoded
        @POST("address/setDefaults")
        Observable<BaseResult> setDefaults(@Field("addressId") String addrId);


        @POST("address/query")
        Observable<BaseResult<List<DefaultSite>>> getDefaultquery();



        @FormUrlEncoded
        @POST("address/add")
        Observable<BaseResult> addAddress( @Field("username") String packageId,
                                            @Field("phone") String phone,
                                            @Field("provinceCode") String provinceCode,
                                            @Field("cityCode") String cityCode,
                                            @Field("countyCode") String countyCode,
                                            @Field("address") String address);

        @FormUrlEncoded
        @POST("address/delete")
        Observable<BaseResult> deleteDddress(@Field("addrId") String addrId);


        @FormUrlEncoded
        @POST("address/edit")
        Observable<BaseResult> editDddress( @Field("addrId") String addrId,
                                            @Field("username") String packageId,
                                            @Field("phone") String phone,
                                            @Field("provinceCode") String provinceCode,
                                            @Field("cityCode") String cityCode,
                                            @Field("countyCode") String countyCode,
                                            @Field("address") String address);


        @FormUrlEncoded
        @POST("address/detail")
        Observable<BaseResult<DefaultSite>> detailDddress(@Field("addressId") String addressId);
    }

    //获取默认地址
    public static Observable<BaseResult<DefaultSite>> getDefaultAddress () {
        return RetrofitFacade.Companion.getRetrofit().create(SiteService.class).getDefaultAddress();
    }


    //获取默认地址
    public static Observable<BaseResult> setDefaults (String addrId) {
        return RetrofitFacade.Companion.getRetrofit().create(SiteService.class).setDefaults(addrId);
    }

    //获取地址列表
    public static Observable<BaseResult<List<DefaultSite>>> getDefaultquery () {
        return RetrofitFacade.Companion.getRetrofit().create(SiteService.class).getDefaultquery();
    }

    //添加新的收货地址
    public static Observable<BaseResult> addAddress (AddressEntity entity) {
        return RetrofitFacade.Companion.getRetrofit().create(SiteService.class).addAddress(entity.getUsername(),
                entity.getPhone(),entity.getProvinceCode(),entity.getCityCode(),entity.getCountyCode(),entity.getAddress());
    }

    //修改地址
    public static Observable<BaseResult> editDddress (AddressEntity entity) {
        return RetrofitFacade.Companion.getRetrofit().create(SiteService.class).editDddress(entity.getAddrId(),entity.getUsername(),
                entity.getPhone(),entity.getProvinceCode(),entity.getCityCode(),entity.getCountyCode(),entity.getAddress());
    }

    //删除地址
    public static Observable<BaseResult> deleteDddress (String address) {
        return RetrofitFacade.Companion.getRetrofit().create(SiteService.class).deleteDddress(address);
    }

    //获取地址详情
    public static Observable<BaseResult<DefaultSite>> detailDddress (String addressId) {
        return RetrofitFacade.Companion.getRetrofit().create(SiteService.class).detailDddress(addressId);
    }

    public static class AddressEntity{

        public String getAddrId(){
            return addrId;
        }

        public void setAddrId(String addrId){
            this.addrId = addrId;
        }

        /**
         * username : 王五
         * phone : 1266666666
         * provinceCode : 360000
         * cityCode : 360100
         * countyCode : 360101
         * address : 江西省南昌市市辖区333号
         */

        private String addrId;
        private String username;
        private String phone;
        private String provinceCode;
        private String cityCode;
        private String countyCode;
        private String address;

        public String getUsername(){
            return username;
        }

        public void setUsername(String username){
            this.username = username;
        }

        public String getPhone(){
            return phone;
        }

        public void setPhone(String phone){
            this.phone = phone;
        }

        public String getProvinceCode(){
            return provinceCode;
        }

        public void setProvinceCode(String provinceCode){
            this.provinceCode = provinceCode;
        }

        public String getCityCode(){
            return cityCode;
        }

        public void setCityCode(String cityCode){
            this.cityCode = cityCode;
        }

        public String getCountyCode(){
            return countyCode;
        }

        public void setCountyCode(String countyCode){
            this.countyCode = countyCode;
        }

        public String getAddress(){
            return address;
        }

        public void setAddress(String address){
            this.address = address;
        }
    }
}
